package minix.pages;

import java.sql.SQLException;
import java.util.List;

import minix.entities.Bilde;

import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
import org.slf4j.Logger;

/**
 * Start page of application pasienlosjen_web.
 */
public class VisBilde extends InlineStreamResponse {

	@Inject
	private Session session;
	@Inject
	private Logger logger;

	@Log
	Object onActivate(Integer id) throws SQLException {
		logger.debug("==================antall:" + session.createCriteria(Bilde.class).list().size());
		List<Bilde> list = session.createCriteria(Bilde.class).list();
		Bilde bilde = list.get(id);
		super.setIs(bilde.getData().getBinaryStream());
		super.setContentType(bilde.getType());
		super.setExtension(bilde.getEndelse());

		return this;
	}

}
